package servlet;

import db.DB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/editgoodstockwarning")//访问的时候给一个地址,高于3.0版本的包才能这么配地址
public class editgoodstockwarning extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        int goodid=Integer.parseInt(req.getParameter("goodid"));
        int amount=Integer.parseInt(req.getParameter("goodamount"));


        HttpSession session=req.getSession();


        if(new DB().editgoodstockwarning(goodid,amount)){
            session.setAttribute("inventorypage","customer");
            resp.sendRedirect("inventory.jsp");
        }
        else{
            String message = "修改失败！可能原因：预警数为负";
            session.setAttribute("message",message);
            resp.sendRedirect("inventory.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp); }
}

